package databaseComm;

import java.sql.Connection;
import java.util.Date;
import java.util.List;

import results.IncorrectProblemStatistic;
import results.Result;

import equations.MathFactsCategory;
import equations.Problem;

import accounts.Account;

/**
 * This interface specifies an API that will interact with the database. 
 * This will be stubbed until an actual implementation is dat.
 * @author stewarte
 *
 */
public interface DatabaseDriverInterface {
	
	
	
	/**
	 * Connects to the database at the given address
	 * @param address
	 * @return
	 */
	boolean connectToDatabase(String username, String password);
	
	/**
	 * This function will poll the database to see whether or not a user is authentic.
	 * If user is not authentic, function will return an account with the account info.
	 * @param username
	 * @param password
	 * @return
	 */
	 Account authenticateLogin(String username, String password);
	 
	 public void exitConnection();
	 
	 /**
	  * Returns true if username is available, false if it is already used
	  * @param username
	  * @return
	  */
	 boolean usernameAvailable(String username);
	
	/**
	 * This function will create a new account. The first argument,
	 * creator, will be used to authenticate whether the creator has
	 * proper clearance to create an account. Account toBeCreated, is the account
	 * we are going to create and add to the database.
	 * 
	 * @return isSuccessful
	 */
	 boolean createAccount(Account creator, Account toBeCreated);
	
	/**
	 * This function will delete an account from the database. First arg,
	 * deleter, will be checked to see if delete clearance is available (i.e. only an
	 * admin can delete an account). Account toBeDeleted contains the information of the
	 * account to be deleted.
	 * 
	 * @return isSuccessful
	 */
	 boolean deleteAccount(Account deleter, String username);
	
	/**
	 * This method will change the password of toBeChanged to newPassword, if changer
	 * has proper authentication to change an account passwords (i.e., if changer is an
	 * admin).
	 * @param changer
	 * @param toBeChanged
	 * @param newPassword
	 * @return
	 */
	 boolean changePassword(Account changer, String username, String newPassword);
	
	/**
	 * Retrieves the password, checks to see if retriever is authorized to 
	 * retrieve passwords (i.e. Admin or Instructor). Returns "NOT_IN_DB"
	 * if unable to retrieve password because username not in database. If unable,
	 * to find a password for any other reason, returns an empty string.
	 * 
	 * @param retriever
	 * @param username
	 * @return password
	 */
	String retrievePassword(Account retriever, String username);
	
	
	/**
	 * Store the result of the session into the database
	 * @return
	 */
	boolean addResult(Result r);
	
	/**
	 * Gets all the results for a given category and user
	 * @param mfc
	 * @return
	 */
	List<Result> getAllResultsForCategory(MathFactsCategory mfc, String username);
	
	/**
	 * Gets all the results for for a given user, irregardless of category
	 * @param mfc
	 * @return
	 */
	List<Result> getAllResults( String username);
	
	/**
	 * Passes in the problem that is incorrect to the database. Checks if the problem is already in the database
	 * for the user. If it is, increment the count wrong. If not, add a new entry with the given problem
	 * for the given user.
	 * @param p
	 * @return
	 */
	boolean addIncorrectEquationResult(Problem p, String username);
	
	/**
	 * Gets the list of incorrect problems and the stats for each incorrect problem, IncorrectProblemStatistic
	 * wraps problem and has a count.
	 * @param username
	 * @return
	 */
	List<IncorrectProblemStatistic> getIncorrectProblemsStatistics(String username);

	MathFactsCategory getAllEquationsForCategory(String string);
	
	
	
}

